package database;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeansException;

import database.dao.PlayerCollectSingerInfoDao;
import database.pojo.PlayerCollectSingerInfo;
import util.JdbcUtils;
import util.MyFactory;

public class PlayerSingerDBServer {
	public boolean insertPlayerCollectSingerInfo(PlayerCollectSingerInfo pInfo) throws SQLException{
		Connection conn = null;
		try{
			System.out.println("insertPlayerCollectSingerInfo");
			conn = MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).getConnection();
			return MyFactory.context.getBean("PlayerCollectSingerInfoDao", PlayerCollectSingerInfoDao.class).insert(pInfo, conn);
		}finally{
			MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).releaseConnection(conn);
		}
	}
	
	public PlayerCollectSingerInfo updatePlayerCollectSingerInfo(PlayerCollectSingerInfo pInfo) throws SQLException{
		Connection conn = null;
		try{
			conn = MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).getConnection();
			MyFactory.context.getBean("PlayerCollectSingerInfoDao", PlayerCollectSingerInfoDao.class).update(pInfo, conn);
		}finally{
			MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).releaseConnection(conn);
		}
		return pInfo;
	}
	
	public ArrayList<PlayerCollectSingerInfo> selectPlayerCollectSingerInfoByOpenId(String openId) throws SQLException{
		Connection conn = null;
		try{
			conn = MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).getConnection();
			return MyFactory.context.getBean("PlayerCollectSingerInfoDao", PlayerCollectSingerInfoDao.class).selectAllByOpenId(openId, conn);
		}finally{
			MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).releaseConnection(conn);
		}
	}
	
	public boolean isExitPlayerCollectSingerInfo(PlayerCollectSingerInfo pInfo) throws SQLException{
		Connection conn = null;
		try{
			conn = MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).getConnection();
			return MyFactory.context.getBean("PlayerCollectSingerInfoDao", PlayerCollectSingerInfoDao.class).isExist(pInfo, conn);
		}finally{
			MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).releaseConnection(conn);
		}
	}
	public boolean delect(String openId, int singerId) throws SQLException{
		Connection conn = null;
		try{
			conn = MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).getConnection();
			return MyFactory.context.getBean("PlayerCollectSingerInfoDao", PlayerCollectSingerInfoDao.class).delete(openId, singerId, conn);
		}finally{
			MyFactory.context.getBean("JdbcUtils",JdbcUtils.class).releaseConnection(conn);
		}
	}
	
	
}